﻿Imports System.Xml

Public Class TextFramePreference
	Private _TextColumnFixedWidth As Double

	Public Property TextColumnFixedWidth As Double
		Get
			Return _TextColumnFixedWidth
		End Get
		Set(value As Double)
			If value >= 0 And value <= 8640 Then
				_TextColumnFixedWidth = value
			Else
				Debug.WriteLine("TextFramePreference.TextColumnFixedWidth cannot accept value: {0}. Value must be between 0 and 8640.", value)
			End If
		End Set
	End Property

	Private Property InsetSpacing As InsetSpacing

	Public Shared Function ReadXml(reader As XmlReader) As TextFramePreference
		Dim tfp As New TextFramePreference()

		If reader.HasAttributes Then
			tfp.TextColumnFixedWidth = Parser.ParseDouble(reader.GetAttribute("TextColumnFixedWidth"))
		End If

		If Not reader.IsEmptyElement Then
			While reader.Read()
				Select Case reader.Name
					Case "Properties"
						While reader.Read()
							Select Case reader.Name
								Case "InsetSpacing"
									tfp.InsetSpacing = InsetSpacing.ReadXml(reader)
								Case "Properties"
									If reader.NodeType = XmlNodeType.EndElement Then
										Exit While
									End If
								Case Else
									If reader.NodeType = XmlNodeType.Element Then
										Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "TextFramePreference - Properties")
									End If
							End Select
						End While
					Case "TextFramePreference"
						If reader.NodeType = XmlNodeType.EndElement Then Exit While
					Case Else
						If reader.NodeType = XmlNodeType.Element Then
							Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "TextFramePreference")
						End If
				End Select
			End While
		End If

		Return tfp
	End Function
End Class
